/**
 * Copyright &copy; 2016 CNJSON All rights reserved.
 */
package com.hongsuan.pplive.modules.live.service;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cnjson.db.service.CrudService;
import com.cnjson.db.persistence.Page;
import com.hongsuan.pplive.modules.live.dao.LiveRoomDao;
import com.hongsuan.pplive.modules.live.entity.LiveRoom;

/**
 * 单表生成Service
 * 
 * @author cgli
 * @version 2016-04-18
 */
@Service
@Transactional(readOnly = true)
public class LiveRoomService extends CrudService<LiveRoomDao, LiveRoom> {

	@Autowired
	private LiveRoomDao dao;

	public LiveRoom get(String id) {
		return super.get(id);
	}

	public List<LiveRoom> findList(LiveRoom liveRoom) {
		return super.findList(liveRoom);
	}

	public Page<LiveRoom> findPage(Page<LiveRoom> page, LiveRoom liveRoom) {
		return super.findPage(page, liveRoom);
	}

	@Transactional(readOnly = false)
	public void save(LiveRoom liveRoom) {
		super.save(liveRoom);
	}

	@Transactional(readOnly = false)
	public void delete(LiveRoom liveRoom) {
		super.delete(liveRoom);
	}

	public LiveRoom getByOwner(String owner) {
		return dao.getByOwner(owner);
	}

	@Transactional(readOnly = false)
	public void join(String roomId, String userId) {
		dao.join(roomId, userId);
	}

	@Transactional(readOnly = false)
	public void leave(String roomId, String userId) {
		dao.leave(roomId, userId);
	}

	/**
	 * 注意是一个ids列表，获取多用户ID的主播房间列表
	 * 
	 * @param userIds
	 *            ('id1','id2','');
	 * @return
	 */
	public List<LiveRoom> getByUserIds(String userIds) {
		userIds = StringUtils.join(userIds.split(","), "','");
		userIds = "'" + userIds + "'";
		return dao.getByUserIds(userIds);
	}

	@Transactional(readOnly = false)
	public void updateStateByUsers(String userIds) {
		dao.updateStateByUsers(userIds);
	}

	public boolean checkExisted(String columnName, String columnValue) {
		int ret = dao.checkExisted(columnName, columnValue);
		return (ret > 0);
	}
}